<template>
	<view class="pbBuylist">
		<view class="pitem" v-for="dt in goods" :key="dt.id">
			<view class="imgbox">
				<image class="minsp" :src="dt.imageUrl" mode="aspectFill"></image>
			</view>
			<view class="content">
				<text class="title">{{dt.name}}</text>
				<view class="priceNum">
					<view class="price">￥
						<text class="txt" v-if="orderInfo.orderType==1">{{dt.unitPrice}}</text>
						<text class="txt" v-else-if="orderInfo.orderType==2">{{dt.price}}</text>
					</view>
					<view class="numbox" :class="{'numbox2':type!=1}">
						<number-selector v-if="type==1" v-model="dt.quantity" @onchange="change"/>
						<text class="num" v-else>x{{dt.quantity}}</text>
					</view> 
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {defineComponent,reactive,toRefs,onMounted,getCurrentInstance,computed} from 'vue'
	import {onLoad,onShow} from '@dcloudio/uni-app'
	import { useStore } from 'vuex'
	import numberSelector from "@/components/numberSelector/numberSelector.vue"
	export default defineComponent({
		components:{
			numberSelector
		},
		props:{
			type:{
				type:Number,
				default:1  // 可编辑购买数量，2不可编辑购买数量
			}
		},
		setup(props,context) {
			const store = useStore()
			const {proxy} = getCurrentInstance()
			
			const state = reactive({
				imgUrlPrefix:getApp().globalData.imgUrlPrefix,
				goods:computed(()=>store.state.base.goods), // 选择的商品
				orderInfo:computed(()=>store.state.base.orderInfo), 
			})
			
			onMounted(()=>{
				
			})
			
			const change = (num)=>{
				if(num == 0) {
					store.commit('base/del_goods')
				}
				if(!state.goods || state.goods.length<1){
					//uni.navigateBack()
					uni.showModal({
						title: '提示',
						content: '至少选择一个商品！',
						showCancel:false,
						success: function (res) {
							if (res.confirm) {
								uni.navigateBack()
							} 
						}
					});
				}
			}
			
			return {
				...toRefs(state),
				change
			}
		}
	})
</script>

<style lang="scss" scoped>
	.pbBuylist{
		width: 100%;
		.pitem{
			display: flex;
			&+.pitem{
				margin-top: 30rpx;
			}
			.imgbox{
				width: 200rpx;
				height: 200rpx;
				border-radius: 20rpx;
				overflow: hidden;
				.imgbox{
					display: block;
					width: 100%;
					height: 100%;
				}
			}
			.content{
				flex: 1;
				align-items: center;
				width: 0;
				padding: 14rpx 0 0 20rpx;
				.title{
					display: block;
					font-size: 34rpx;
					font-weight: 600;
					height: 90rpx;
					text-overflow: -o-ellipsis-lastline;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					line-clamp: 2;
					-webkit-box-orient: vertical;
				}
				.priceNum{
					display: flex;
					align-items: center;
					padding: 15rpx 0 0 0;
					.price{
						flex:1;
						font-size: 28rpx;
						font-weight: bold;
						color: #ff0000;
						.txt{
							font-size: 40rpx;
						}
					}
					.numbox{
						width: 220rpx;
						&.numbox2{
							width: auto;
						}
					}
				}
			}
		}
	}
</style>
